Skip to content

Conversation

treyshaffer
Copy link

Fixed color inconsistency in verbose mode where test status showed green instead of yellow for passed tests with warnings.

closes #13201

@psf-chronographer psf-chronographer bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Oct 16, 2025
@treyshaffer treyshaffer force-pushed the fix-warning-color-13201 branch 12 times, most recently from 1584ced to f08f4ca Compare October 16, 2025 21:29
@bluetech
Copy link
Member

Thanks for the PR @treyshaffer but this is not an approach we can accept, as it side-steps the entire "flow" of the reports in order to add record this information early. I will leave a comment describing why this happens in the issue, we can discuss other approaches there. We may want to use your tests for the eventual solution.

@bluetech bluetech closed this Oct 18, 2025
@bluetech bluetech reopened this Oct 18, 2025
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about it more I think the approach can be adapted to a possible solution.

Basically, the idea of stashing the log recorder seems workable, but we shouldn't use user properties for this like the current PR does.

The fix should be entirely confined to the warnings plugin, the terminal code shouldn't need to change.

Basically what we want is to dispatch the pytest_warning_recorded hook calls earlier, not just at the end of runtest_protocol. So stash the warnings records, treating it as a "queue", and then "process" it in e.g. pytest_runtest_makereport (not sure it's the best place but possible).

@treyshaffer
Copy link
Author

After thinking about it more I think the approach can be adapted to a possible solution.

Basically, the idea of stashing the log recorder seems workable, but we shouldn't use user properties for this like the current PR does.

The fix should be entirely confined to the warnings plugin, the terminal code shouldn't need to change.

Basically what we want is to dispatch the pytest_warning_recorded hook calls earlier, not just at the end of runtest_protocol. So stash the warnings records, treating it as a "queue", and then "process" it in e.g. pytest_runtest_makereport (not sure it's the best place but possible).

Thanks for the feedback, you have a good point, and I like that approach more. I'll try to implement it this way and push a new revision

@treyshaffer treyshaffer force-pushed the fix-warning-color-13201 branch from 0000154 to 8df2e57 Compare October 20, 2025 21:05
Fixed issue where test status showed green instead of yellow for passed
tests with warnings in verbose mode. Tests with warnings now correctly
display in yellow both during progress and in the final summary.

Changes:
- Added pytest_report_teststatus hook with tryfirst=True to provide yellow
  markup for passed tests that have warnings
- Set has_warnings attribute on TestReport for xdist compatibility
- Added color logic in _determine_main_color to keep progress green while
  running in verbose mode
- Moved TestReport and CallInfo imports out of TYPE_CHECKING block for
  100% coverage
- Removed unused _nodeids_with_warnings global state (memory leak fix)
- Updated test to verify has_warnings attribute directly

Fixes pytest-dev#13201

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@treyshaffer treyshaffer force-pushed the fix-warning-color-13201 branch from 8df2e57 to 78af87a Compare October 20, 2025 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

color of percentage on warning is green with -v

2 participants